package com.xiao.kafka.consumer.message;

import com.xiao.common.utils.JsonUtils;
import com.xiao.kafka.producer.constant.KafkaProducerTopic;
import com.xiao.kafka.producer.vo.TestMessageVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;


/**
 * @Description kafka消息消费者
 * @Auther: 笑笑是一个码农
 * @Date: 15:25 2021/1/8
 */
@Slf4j
@Component
public class KafkaConsumer {

    /**
     * 消息消费者，监听消息生产者中定义的topic，topics同时可以监听多个
     * @param message
     */
    @KafkaListener(topics = KafkaProducerTopic.TEST_TOPIC)
    public void consumer(String message){
        log.info("[ kaka消费者服务 ] 接收到消息, topic: {}, message: {}", KafkaProducerTopic.TEST_TOPIC, message);
        log.info("[ kaka消费者服务 ] 反序列化消息, messageVo: {}", JsonUtils.parseFlex(message, TestMessageVo.class));
    }
}
